// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Element/CPENTAParser.h"

#include "gtest/gtest.h"

#include "DataStructure/Input/Element/CPENTAData.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
using namespace SG::DataStructure::FEM;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class CPENTAParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        DB_SERVICEFACTORY->ClearDatabase ();
    }
};

TEST_F (CPENTAParserTest, ParseEntry1)
{
    std::vector<std::string> Entry = { "CPENTA   85974  13245016 32871   32872   33781   32884   32885   33792" };

    SG::DataStructure::FEM::CPENTA6Data data;
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCPENTA (DB_SERVICEFACTORY, dividedEntryInfo);

    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (0, data);

    ASSERT_TRUE (data.m_id == 85974);
    ASSERT_TRUE (data.m_pId == 13245016);
    ASSERT_TRUE (data.m_g[0] == 32871);
    ASSERT_TRUE (data.m_g[1] == 32872);
    ASSERT_TRUE (data.m_g[2] == 33781);
    ASSERT_TRUE (data.m_g[3] == 32884);
    ASSERT_TRUE (data.m_g[4] == 32885);
    ASSERT_TRUE (data.m_g[5] == 33792);
}

TEST_F (CPENTAParserTest, ParseEntry2)
{
    std::vector<std::string> Entry = { "CPENTA         1       1       4       2       5       9       7      10+000006D",
                                       "+000006D      64      61      60      25      36      59      22      35+000006E",
                                       "+000006E      24" };

    SG::DataStructure::FEM::CPENTA15Data data;
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCPENTA (DB_SERVICEFACTORY, dividedEntryInfo);

    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (0, data);

    ASSERT_TRUE (data.m_id == 1);
    ASSERT_TRUE (data.m_pId == 1);
    ASSERT_TRUE (data.m_g[0] == 4);
    ASSERT_TRUE (data.m_g[1] == 2);
    ASSERT_TRUE (data.m_g[2] == 5);
    ASSERT_TRUE (data.m_g[3] == 9);
    ASSERT_TRUE (data.m_g[4] == 7);
    ASSERT_TRUE (data.m_g[5] == 10);
    ASSERT_TRUE (data.m_g[6] == 64);
    ASSERT_TRUE (data.m_g[7] == 61);
    ASSERT_TRUE (data.m_g[8] == 60);
    ASSERT_TRUE (data.m_g[9] == 25);
    ASSERT_TRUE (data.m_g[10] == 36);
    ASSERT_TRUE (data.m_g[11] == 59);
    ASSERT_TRUE (data.m_g[12] == 22);
    ASSERT_TRUE (data.m_g[13] == 35);
    ASSERT_TRUE (data.m_g[14] == 24);
}